/*!
    \copyright  Copyright (c) 2023 Qualcomm Technologies International, Ltd.
                All Rights Reserved.
                Qualcomm Technologies International, Ltd. Confidential and Proprietary.
    \file
    \ingroup    leabm
    \brief      The events sent from the le broadcast manager using the Event Bus
*/

#if defined(INCLUDE_LE_AUDIO_BROADCAST)

#include "le_broadcast_manager_source.h"
#include "le_audio_core_channel_event_spec.h"
#include "event_bus_publish.h"
#include "le_broadcast_send_event.h"
#include <logging.h>

/*! \brief Send message through Event Bus.

 \param event event bus event to publish.
 \param data data associated with the event
 \param data_size size of the data
 
 */
static void leBroadcastManager_PublishEvent(le_audio_core_event_t event, void * data, uint16 data_size)
{
    EventBus_Publish(EVENT_BUS_CHANNEL_LE_AUDIO_CORE, event, data, data_size);
}

void leBroadcastManager_SendSetupDataPathCommandCompletEvent(BapServerSetupDataPathCfm *cfm)
{
    LE_AUDIO_CORE_COMMAND_COMPLETE_T event = {0};

    event.command = le_audio_core_setup_iso_data_path;
    event.status = cfm->status;
    event.conn_handle = cfm->isoHandle;

    DEBUG_LOG("leBroadcastManager_SendSetupDataPathCommandCompletEvent");
    leBroadcastManager_PublishEvent(le_audio_core_command_complete, &event, sizeof(LE_AUDIO_CORE_COMMAND_COMPLETE_T));
}

void leBroadcastManager_SendBigSyncLossEvent(BapServerIsocBigTerminateSyncInd *ind)
{
    le_audio_core_big_sync_lost_t params =
    {
        .reason = ind->status,
        .big_handle = ind->bigHandle,
    };

    DEBUG_LOG("leBroadcastManager_SendBigSyncLossEvent");
    leBroadcastManager_PublishEvent(le_audio_core_big_sync_lost, &params, sizeof(params));
}
#endif /* INCLUDE_LE_AUDIO_BROADCAST */

